package com.ch04.config;

import com.ch04.interceptor.Interceptor1;
import com.ch04.interceptor.Interceptor2;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Jane
 * @date 2024-05-29 17:23
 */
//@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
  //  @Bean
    public Interceptor1 interceptor1(){
        return new Interceptor1();
    }

   // @Bean
    public Interceptor2 interceptor2(){
        return new Interceptor2();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //WebMvcConfigurer.super.addInterceptors(registry);
        String[] paths={"/**","/backenduser/*" }; //要拦截的url
        String[] exportPaths={"/statics/**","*/login","/backend/test","/devuser/*","/templates/**"}; //不要拦截的url

        registry.addInterceptor(interceptor1())
                                .addPathPatterns(paths)
                                .excludePathPatterns(exportPaths);


        registry.addInterceptor(interceptor2())
                .addPathPatterns(paths)
                .excludePathPatterns(exportPaths);//exclude 排除指定路径

//        registry.addInterceptor(new Interceptor1());
    }
}
